package com.enums;

import com.modeldiy.Selector;
import com.utils.ReturnCodeUtils;
import org.apache.commons.collections.map.HashedMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  ajax请求返回码   只有0是没有错误，表示成功
 */
public enum ReturnCode {
/** 请求成功  0 */
    SUCCESS {
        @Override
        public String toString() {
            return "成功";
        }
    },
    FAIL{
        @Override
        public String toString() {
            return "操作失败";
        }
    },
    EXISTS{
        @Override
        public String toString() {
            return "已经存在";
        }
    },
    SUCCESS_MODIFY {
        @Override
        public String toString() {
            return "更新成功";
        }
    },
    FAIL_MODIFY {
        @Override
        public String toString() {
            return "更新失败";
        }
    },
    SUCCESS_ADD {
        @Override
        public String toString() {
            return "新增成功";
        }
    },
    FAIL_ADD {
        @Override
        public String toString() {
            return "新增失败";
        }
    },
    SUCCESS_DEL {
        @Override
        public String toString() {
            return "删除成功";
        }
    },
    FAIL_DEL {
        @Override
        public String toString() {
            return "删除失败";
        }
    };
    @Override
    public String toString(){
        return this.toString();
    }

    public Integer getValue(){
        return ordinal();
    }

    /**
     * 获取对应枚举数据如果没有就默认第一个
     * @param value
     * @return
     */
    public static ReturnCode valueOf(Integer value){
        ReturnCode[] models=ReturnCode.values();
        if(value==null){
            return models[0];
        }
        for (ReturnCode model : models) {
            if (value.equals(model.getValue())) {
                return model;
            }
        }
        return models[0];
    }
    public static List getSelect(){
        List list=new ArrayList<InType>();
        ReturnCode[] objs=ReturnCode.values();
        for (ReturnCode obj : objs) {
            Selector selector=new Selector();
            selector.setId(obj.getValue());
            selector.setName(obj.toString());
            list.add(selector);
        }
        return list;
    }
    public static Map getMap(){
        Map<String,String> map=new HashMap<String,String>();
        ReturnCode[] objs=ReturnCode.values();
        for (ReturnCode obj : objs) {
            map.put(obj.name(),obj.toString());
            System.out.println(obj.name()+obj.getValue());
        }
        return map;
    }
    public static void main (String[] args) {
//        Map<String,Object> result=new HashMap<String,Object>();
//        result.put("model","model");
//        ReturnCodeUtils.setReturnCode(result,ReturnCode.SUCCESS_ADD);
//        System.out.println(result.get("msg"));
        getMap();
    }
}
